<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>数学内置对象</title>
</head>

<body>
  <script>
    // 圆周率
    console.log(Math.PI);
    // 向上取整
    console.log(Math.ceil(1.2));  //2
    // 向下取整
    console.log(Math.floor(1.9)); //1
    // 四舍五入取整
    console.log(Math.round(1.5)); //1

    // Math.floor取整和parseInt取整区别
    // 1.Math.floor只能取整数字
    // 2.parseInt可以取整字符串

    console.log('=====随机数=====');
    let ran = Math.floor(Math.random() * 11)
    console.log(ran);

    console.log('=====随机数组=====');
    let arr = ['张三', '李四', '王五']
    let random = Math.floor(Math.random() * arr.length)
    console.log(arr[random]);

    console.log('=====随机两个数(公式)=====');
    function getRandom(N, M) {
      return Math.floor(Math.random() * (M - N + 1) + N)
    }
    console.log(getRandom(4, 7));
  </script>
</body>

</html>